package android.session.txtdisp;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {

	public final  static String EXTRA_MESSAGE = "com.example.myfirstap.MSG";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    /* This method will be invoked upon pressing send_button */
    public void sendMessage (View view)
    {
    	/*The constructor used here takes two parameters:
			1) A Context as its first parameter (this is used because the Activity class is a subclass of Context)
			2) The Class of the app component to which the system should deliver the Intent (in this case, the activity that should be started)*/
    	Intent intent = new Intent(this, MessageDisplay.class);
    	
    	/* Before starting the new activity, you have to send bundle of data within this intent,
    	 * So you have to get the input string that the user enters through edit text*/
    	EditText editText = (EditText)findViewById(R.id.edit_message);
    	String message = editText.getText().toString();
    	intent.putExtra(EXTRA_MESSAGE, message);

    	/* start the new activity*/
    	startActivity(intent);
    }
}
